<?php

namespace app\modules\clinical\models;

use Yii;

/**
 * This is the model class for table "visit_info".
 *
 * @property integer $pk_id
 * @property integer $pt_id
 * @property string $pt_history
 * @property string $pt_body
 * @property string $pt_solution
 * @property string $visit_memo
 * @property string $crt_name
 * @property string $crt_time
 */
class VisitInfo extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'visit_info';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pt_id', 'pt_history', 'pt_body', 'pt_solution', 'visit_memo'], 'required'],
            [['pt_id'], 'integer'],
            [['crt_time'], 'safe'],
            [['pt_history', 'pt_body', 'pt_solution', 'visit_memo'], 'string', 'max' => 255],
            [['crt_name'], 'string', 'max' => 10]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'pk_id' => 'Pk ID',
            'pt_id' => 'Pt ID',
            'pt_history' => '现病史',
            'pt_body' => '体格检查',
            'pt_solution' => '处理',
            'visit_memo' => '注意事项',
            'crt_name' => '创建人',
            'crt_time' => '创建时间',
        ];
    }

    public function beforeSave($insert)
    {
        if(parent::beforeSave($insert)){
            if($this->isNewRecord){

                $this->crt_time = date('y-m-d H:i:s');
                $this->crt_name = Yii::$app->user->identity->username;
            }
            return true;
        }else{

            return false;
        }
    }
}
